package com.qcrud.core.type;

import java.util.HashMap;
import java.util.Map;

public class FieldTypeHandler {

    private static final Map<String, TypeHandler> TYPE_HANDLER = new HashMap<>() {{
        put("java.lang.String", new StringTypeHandler());
        put("java.lang.Integer", new IntegerTypeHandler());
        put("java.lang.Long", new LongTypeHandler());
        put("java.lang.Boolean", new BooleanTypeHandler());
        put("java.math.BigDecimal", new BigDecimalTypeHandler());
        put("java.lang.Double", new DoubleTypeHandler());
        put("java.lang.Float", new FloatTypeHandler());
        put("java.lang.Short", new ShortTypeHandler());
        put("java.math.BigInteger", new BigIntegerTypeHandler());
        put("java.util.Date", new DateTypeHandler());
        put("java.sql.Timestamp", new LocalDateTimeTypeHandler());
        put("java.time.LocalDate", new LocalDateTypeHandler());
        put("java.time.LocalTime", new LocalTimeTypeHandler());
        put("java.time.Month", new MonthTypeHandler());
        put("java.sql.Clob", new ClobTypeHandler());
        put("java.sql.Character", new CharacterTypeHandler());
    }};

    public static void put(Class<?> clazz, TypeHandler typeHandler) {
        TYPE_HANDLER.put(clazz.getSimpleName(), typeHandler);

    }

    public static TypeHandler get(String className) {
        return null == className ? null : TYPE_HANDLER.get(className);
    }
}
